<?php

/**
 * ExtGridPanelBase class file
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 *          EVALUATION VERSION - NOT FOR COMMERCIAL USE OR DISTRIBUTION.
 * @version 0.7.2
 */
abstract class ExtGridPanelBase extends ExtPanel
{
    private $_selectionmodel_class_types = array('ExtRowSelectionModel',
        'ExtCheckboxSelectionModel', 'ExtCellSelectionModel');
    private $_column_model_class_types = array('ExtGridColumnModel', 'ExtPropertyColumnModel', 'ExtGridLockingColumnModel');
    private $_view_class_types = array('ExtGridView', 'ExtGroupingView');

    private $_addedColumns = array();

    public function addColumn($data)
    {
        $this->_addedColumns[] = $data;
    }

    public function getAddedColumns()
    {
        return $this->_addedColumns;
    }

    public function parseNode(ExtHTMLParserNode $node, ExtASTWalker $astwalker)
    {
        $this->parseSelectionModel($node, $astwalker);
        $this->parseView($node, $astwalker);
        $this->parseLoadMask();
        $this->parseParameters($node, $astwalker, 'viewconfig', 'viewConfig', array('ExtParameter'));
        $this->parseColumnModel($node, $astwalker);
        $this->parseContextMenus($node, $astwalker);
        parent::parseNode($node, $astwalker);
    }

    private function parseContextMenus($node, $astwalker)
    {
        parent::parseContextMenu($node, $astwalker, 'cellcontextmenu', 'cellContextMenu','cellcontextmenu');
        parent::parseContextMenu($node, $astwalker, 'rowcontextmenu', 'rowContextMenu','rowcontextmenu');
        parent::parseContextMenu($node, $astwalker, 'containercontextmenu', 'containerContextMenu','containercontextmenu');
        parent::parseContextMenu($node, $astwalker, 'groupcontextmenu', 'groupContextMenu','groupcontextmenu');
        parent::parseContextMenu($node, $astwalker, 'headercontextmenu', 'headerContextMenu','headercontextmenu');
        parent::parseContextMenu($node, $astwalker, 'rowBodycontextmenu', 'rowBodyContextMenu','rowBodycontextmenu');
    }

    private function parseSelectionModel($node, $astwalker)
    {
        $selmod = $node->findPropertyByName('selectionmodel');
        if (!is_null($selmod))
        {
            $items = parent::parseNodeWidthTag($selmod,
                            $astwalker,
                            true,
                            array('asobject' => true),
                            $this,
                            $this->_selectionmodel_class_types);

            $this->setJavaScriptConfig('selModel', $items[0]);
            $selmod->shiftUp();
        }
    }

    private function parseColumnModel($node, $astwalker)
    {
        $cmprop = $node->findPropertyByName('columnmodel');
        if (!is_null($cmprop))
        {
            $items = parent::parseNodeWidthTag($cmprop,
                            $astwalker,
                            true,
                            array('asobject' => true),
                            $this,
                            $this->_column_model_class_types);
            $this->setJavaScriptConfig('colModel', $items[0]);
            $cmprop->shiftUp();
        }
    }

    private function parseView($node, $astwalker)
    {
        /*
         * cannot be lqazy loaded fro now because of ExtJS
         */
        $view = $node->findPropertyByName('view');
        if (!is_null($view))
        {
            $items = parent::parseNodeWidthTag($view,
                            $astwalker,
                            true,
                            array('asobject' => true),
                            $this);
            $this->setJavaScriptConfig('view', $items[0]);
            $view->shiftUp();
        }
    }

    private function parseLoadMask()
    {
        if ($this->getShowLoadMask())
        {
            $msg = $this->getLoadMaskMsg();
            if (!is_null($msg) && $msg != "")
            {
                $this->setObjectConfig('loadMask', array('msg' => $msg));
            }
            else
            {
                $this->setConfig('loadMask', true);
            }
            $this->deleteConfig('showLoadMask');
            $this->deleteConfig('loadMaskMsg');
        }
    }
}
?>
